package 滑动窗口;

import java.util.Scanner;

public class test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int k = in.nextInt();
        System.out.println(longestOnes(nums,k));
    }
    public static int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int count = 0;//用来记录当前的和
        int result = 0;
        for(int left=0,right=0;right<n;right++){
            if(nums[right]==0) count++;
            while (count>k){
                if (nums[left++]==0) count--;
            }
            result = Math.max(result,right-left+1);
        }
        return result;
    }
}
